﻿using B.S.Backtrack.Domain.Entities;
using B.S.Backtrack.ErrorCode;
using B.S.Backtrack.Infrastructure.Interface;
using B.S.Backtrack.Read.API.Application.Command.Firms;
using MediatR;

namespace B.S.Backtrack.Read.API.Application.CommandHandler.Firms
{
    public class QueryProcesFileHandler : IRequestHandler<QueryProcesFileCommand, ApiResult<List<Firm>>>
    {
        private readonly IBaseRepository<Firm> fiRep;

        public QueryProcesFileHandler(IBaseRepository<Firm> fiRep)
        {
            this.fiRep = fiRep;
        }
        public Task<ApiResult<List<Firm>>> Handle(QueryProcesFileCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Firm>> result = new ApiResult<List<Firm>>();
            var list = fiRep.GetAll().Where(x => x.ProductId == request.ProductId && !x.IsDel);
            result.Code = ApiEnums.查询成功;
            result.Msg = ApiEnums.查询成功.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
